package action;

import java.util.HashMap;
import java.util.List;

import model.Department;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import service.DeptService;
import action.base.BaseAction;

@Controller
@Scope("prototype")
public class DeptAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Autowired
	private DeptService deptService;
	private boolean success = false;
	private Department department;
	private List<HashMap<String, Object>> list;
	private List<Department> deptList;

	/**
	 * 列表中的树形结构
	 * 
	 * @return
	 */
	public String queryTree() {
		Integer id = getParameterInt("node");
		setList(deptService.queryTree(id));
		return "list";
	}

	/**
	 * 新增修改的树形结构
	 * 
	 * @return
	 */
	public String getTreeBypid() {
		setDeptList(deptService.getTreeBypid(1));
		return "deptList";
	}

	/**
	 * 保存单位信息
	 * 
	 * @return
	 */
	public String saveOrUpdate() {
		deptService.saveOrUpdate(department);
		success = true;
		return "success";
	}

	public DeptService getDeptService() {
		return deptService;
	}

	public void setDeptService(DeptService deptService) {
		this.deptService = deptService;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

	public List<HashMap<String, Object>> getList() {
		return list;
	}

	public void setList(List<HashMap<String, Object>> list) {
		this.list = list;
	}

	public List<Department> getDeptList() {
		return deptList;
	}

	public void setDeptList(List<Department> deptList) {
		this.deptList = deptList;
	}

}
